import Vue from "vue";
import Router from "vue-router";

import Login from "../views/Login"
import Index from "../views/Index"
import Map from "../views/child/Map"
import Detail from "../views/child/Detail"
import Statistics from "../views/child/Statistics"

Vue.use(Router);

export default new Router({
	routes: [
		{ path: "/", component: Login, meta: { title: '登录'} },
		{
            path: "/index",
            component: Index,
            alias:'/index/*',
            children:[
                {path:'',component:Map,meta:{keepAlive:true}},
                {path:'detail/:id',component:Detail},
                {path:'statistics/:id',component:Statistics},
            ]
        }
	],
	scrollBehavior(to, from, savedPosition) {
		if (savedPosition) {
		    return savedPosition
		} else {
			if (from.meta.keepAlive) {
				from.meta.savedPosition = document.getElementsByClassName('page')[0].scrollTop;
			}
		    return { x: 0, y: to.meta.savedPosition || 0 }
		}
	}
});
